home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_apache.idb / usr / freeware / catman / p_man / cat3 / regex.Z / regex
Encoding:
Text File  |  1999-07-16  |  18.8 KB  |  463 lines

  1.  
  2.  
  3.  
  4.      RRRREEEEGGGGEEEEXXXX((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11117777 MMMMaaaayyyy 1111999999993333))))          RRRREEEEGGGGEEEEXXXX((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       regcomp, regexec, regerror, regfree -    regular-expression
  10.       library
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.       ####iiiinnnncccclllluuuuddddeeee <<<<ssssyyyyssss////ttttyyyyppppeeeessss....hhhh>>>>
  14.       ####iiiinnnncccclllluuuuddddeeee <<<<rrrreeeeggggeeeexxxx....hhhh>>>>
  15.  
  16.       int regcomp(regex_t *preg, const char    *pattern, int cflags);
  17.  
  18.       int regexec(const regex_t *preg, const char *string,
  19.             size_t nmatch, regmatch_t pmatch[],    int eflags);
  20.  
  21.       size_t regerror(int errcode, const regex_t *preg,
  22.             char *errbuf, size_t errbuf_size);
  23.  
  24.       void regfree(regex_t *preg);
  25.  
  26.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  27.       These    routines implement POSIX 1003.2    regular    expressions
  28.       (``RE''s); see _r_e_g_e_x(7).  _R_e_g_c_o_m_p compiles an    RE written as
  29.       a string into    an internal form, _r_e_g_e_x_e_c matches that
  30.       internal form    against    a string and reports results, _r_e_g_e_r_r_o_r
  31.       transforms error codes from either into human-readable
  32.       messages, and    _r_e_g_f_r_e_e    frees any dynamically-allocated
  33.       storage used by the internal form of an RE.
  34.  
  35.       The header <_r_e_g_e_x._h> declares    two structure types, _r_e_g_e_x__t
  36.       and _r_e_g_m_a_t_c_h__t, the former for compiled internal forms and
  37.       the latter for match reporting.  It also declares the    four
  38.       functions, a type _r_e_g_o_f_f__t, and a number of constants    with
  39.       names    starting with ``REG_''.
  40.  
  41.       _R_e_g_c_o_m_p compiles the regular expression contained in the
  42.       _p_a_t_t_e_r_n string, subject to the flags in _c_f_l_a_g_s, and places
  43.       the results in the _r_e_g_e_x__t structure pointed to by _p_r_e_g.
  44.       _C_f_l_a_g_s is the    bitwise    OR of zero or more of the following
  45.       flags:
  46.  
  47.       REG_EXTENDED    Compile    modern (``extended'') REs, rather than
  48.             the obsolete (``basic'') REs that are the
  49.             default.
  50.  
  51.       REG_BASIC    This is    a synonym for 0, provided as a
  52.             counterpart to REG_EXTENDED to improve
  53.             readability.
  54.  
  55.       REG_NOSPEC    Compile    with recognition of all    special
  56.             characters turned off.    All characters are
  57.             thus considered    ordinary, so the ``RE''    is a
  58.             literal    string.     This is an extension,
  59.             compatible with    but not    specified by POSIX
  60.  
  61.  
  62.  
  63.      Page 1                          (printed 5/3/99)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      RRRREEEEGGGGEEEEXXXX((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11117777 MMMMaaaayyyy 1111999999993333))))          RRRREEEEGGGGEEEEXXXX((((3333))))
  71.  
  72.  
  73.  
  74.             1003.2,    and should be used with    caution    in
  75.             software intended to be    portable to other
  76.             systems.  REG_EXTENDED and REG_NOSPEC may not
  77.             be used    in the same call to _r_e_g_c_o_m_p.
  78.  
  79.       REG_ICASE    Compile    for matching that ignores upper/lower
  80.             case distinctions.  See    _r_e_g_e_x(7).
  81.  
  82.       REG_NOSUB    Compile    for matching that need only report
  83.             success    or failure, not    what was matched.
  84.  
  85.       REG_NEWLINE    Compile    for newline-sensitive matching.     By
  86.             default, newline is a completely ordinary
  87.             character with no special meaning in either
  88.             REs or strings.     With this flag, `[^' bracket
  89.             expressions and    `.' never match    newline, a `^'
  90.             anchor matches the null    string after any
  91.             newline    in the string in addition to its
  92.             normal function, and the `$' anchor matches
  93.             the null string    before any newline in the
  94.             string in addition to its normal function.
  95.  
  96.       REG_PEND    The regular expression ends, not at the    first
  97.             NUL, but just before the character pointed to
  98.             by the _r_e__e_n_d_p member of the structure pointed
  99.             to by _p_r_e_g.  The _r_e__e_n_d_p member    is of type
  100.             _c_o_n_s_t _c_h_a_r *.  This flag permits inclusion of
  101.             NULs in    the RE;    they are considered ordinary
  102.             characters.  This is an    extension, compatible
  103.             with but not specified by POSIX    1003.2,    and
  104.             should be used with caution in software
  105.             intended to be portable    to other systems.
  106.  
  107.       When successful, _r_e_g_c_o_m_p returns 0 and fills in the
  108.       structure pointed to by _p_r_e_g.     One member of that structure
  109.       (other than _r_e__e_n_d_p) is publicized:  _r_e__n_s_u_b,    of type
  110.       _s_i_z_e__t, contains the number of parenthesized subexpressions
  111.       within the RE    (except    that the value of this member is
  112.       undefined if the REG_NOSUB flag was used).  If _r_e_g_c_o_m_p
  113.       fails, it returns a non-zero error code; see DIAGNOSTICS.
  114.  
  115.       _R_e_g_e_x_e_c matches the compiled RE pointed to by    _p_r_e_g against
  116.       the _s_t_r_i_n_g, subject to the flags in _e_f_l_a_g_s, and reports
  117.       results using    _n_m_a_t_c_h,    _p_m_a_t_c_h,    and the    returned value.     The
  118.       RE must have been compiled by    a previous invocation of
  119.       _r_e_g_c_o_m_p.  The    compiled form is not altered during execution
  120.       of _r_e_g_e_x_e_c, so a single compiled RE can be used
  121.       simultaneously by multiple threads.
  122.  
  123.       By default, the NUL-terminated string    pointed    to by _s_t_r_i_n_g
  124.       is considered    to be the text of an entire line, minus    any
  125.       terminating newline.    The _e_f_l_a_g_s argument is the bitwise OR
  126.  
  127.  
  128.  
  129.      Page 2                          (printed 5/3/99)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      RRRREEEEGGGGEEEEXXXX((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11117777 MMMMaaaayyyy 1111999999993333))))          RRRREEEEGGGGEEEEXXXX((((3333))))
  137.  
  138.  
  139.  
  140.       of zero or more of the following flags:
  141.  
  142.       REG_NOTBOL    The first character of the string is not the
  143.             beginning of a line, so    the `^'    anchor should
  144.             not match before it.  This does    not affect the
  145.             behavior of newlines under REG_NEWLINE.
  146.  
  147.       REG_NOTEOL    The NUL    terminating the    string does not    end a
  148.             line, so the `$' anchor    should not match
  149.             before it.  This does not affect the behavior
  150.             of newlines under REG_NEWLINE.
  151.  
  152.       REG_STARTEND    The string is considered to start at _s_t_r_i_n_g +
  153.             _p_m_a_t_c_h[0]._r_m__s_o    and to have a terminating NUL
  154.             located    at _s_t_r_i_n_g + _p_m_a_t_c_h[0]._r_m__e_o (there
  155.             need not actually be a NUL at that location),
  156.             regardless of the value    of _n_m_a_t_c_h.  See    below
  157.             for the    definition of _p_m_a_t_c_h and _n_m_a_t_c_h.  This
  158.             is an extension, compatible with but not
  159.             specified by POSIX 1003.2, and should be used
  160.             with caution in    software intended to be
  161.             portable to other systems.  Note that a    non-
  162.             zero _r_m__s_o does    not imply REG_NOTBOL;
  163.             REG_STARTEND affects only the location of the
  164.             string,    not how    it is matched.
  165.  
  166.       See _r_e_g_e_x(7) for a discussion    of what    is matched in
  167.       situations where an RE or a portion thereof could match any
  168.       of several substrings    of _s_t_r_i_n_g.
  169.  
  170.       Normally, _r_e_g_e_x_e_c returns 0 for success and the non-zero
  171.       code REG_NOMATCH for failure.     Other non-zero    error codes
  172.       may be returned in exceptional situations; see DIAGNOSTICS.
  173.  
  174.       If REG_NOSUB was specified in    the compilation    of the RE, or
  175.       if _n_m_a_t_c_h is 0, _r_e_g_e_x_e_c ignores the _p_m_a_t_c_h argument (but see
  176.       below    for the    case where REG_STARTEND    is specified).
  177.       Otherwise, _p_m_a_t_c_h points to an array of _n_m_a_t_c_h structures of
  178.       type _r_e_g_m_a_t_c_h__t.  Such a structure has at least the members
  179.       _r_m__s_o    and _r_m__e_o, both    of type    _r_e_g_o_f_f__t (a signed arithmetic
  180.       type at least    as large as an _o_f_f__t and a _s_s_i_z_e__t),
  181.       containing respectively the offset of    the first character of
  182.       a substring and the offset of    the first character after the
  183.       end of the substring.     Offsets are measured from the
  184.       beginning of the _s_t_r_i_n_g argument given to _r_e_g_e_x_e_c.  An empty
  185.       substring is denoted by equal    offsets, both indicating the
  186.       character following the empty    substring.
  187.  
  188.       The 0th member of the    _p_m_a_t_c_h array is    filled in to indicate
  189.       what substring of _s_t_r_i_n_g was matched by the entire RE.
  190.       Remaining members report what    substring was matched by
  191.       parenthesized    subexpressions within the RE; member _i reports
  192.  
  193.  
  194.  
  195.      Page 3                          (printed 5/3/99)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      RRRREEEEGGGGEEEEXXXX((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11117777 MMMMaaaayyyy 1111999999993333))))          RRRREEEEGGGGEEEEXXXX((((3333))))
  203.  
  204.  
  205.  
  206.       subexpression    _i, with    subexpressions counted (starting at 1)
  207.       by the order of their    opening    parentheses in the RE, left to
  208.       right.  Unused entries in the    array-corresponding either to
  209.       subexpressions that did not participate in the match at all,
  210.       or to    subexpressions that do not exist in the    RE (that is,
  211.       _i > _p_r_e_g->_r_e__n_s_u_b)-have both _r_m__s_o and _r_m__e_o set to -1.  If
  212.       a subexpression participated in the match several times, the
  213.       reported substring is    the last one it    matched.  (Note, as an
  214.       example in particular, that when the RE `(b*)+' matches
  215.       `bbb', the parenthesized subexpression matches each of the
  216.       three    `b's and then an infinite number of empty strings
  217.       following the    last `b', so the reported substring is one of
  218.       the empties.)
  219.  
  220.       If REG_STARTEND is specified,    _p_m_a_t_c_h must point to at    least
  221.       one _r_e_g_m_a_t_c_h__t (even if _n_m_a_t_c_h is 0 or REG_NOSUB was
  222.       specified), to hold the input    offsets    for REG_STARTEND.  Use
  223.       for output is    still entirely controlled by _n_m_a_t_c_h; if    _n_m_a_t_c_h
  224.       is 0 or REG_NOSUB was    specified, the value of    _p_m_a_t_c_h[0] will
  225.       not be changed by a successful _r_e_g_e_x_e_c.
  226.  
  227.       _R_e_g_e_r_r_o_r maps    a non-zero _e_r_r_c_o_d_e from    either _r_e_g_c_o_m_p or
  228.       _r_e_g_e_x_e_c to a human-readable, printable message.  If _p_r_e_g is
  229.       non-NULL, the    error code should have arisen from use of the
  230.       _r_e_g_e_x__t pointed to by    _p_r_e_g, and if the error code came from
  231.       _r_e_g_c_o_m_p, it should have been the result from the most    recent
  232.       _r_e_g_c_o_m_p using    that _r_e_g_e_x__t.  (_R_e_g_e_r_r_o_r may be    able to    supply
  233.       a more detailed message using    information from the _r_e_g_e_x__t.)
  234.       _R_e_g_e_r_r_o_r places the NUL-terminated message into the buffer
  235.       pointed to by    _e_r_r_b_u_f,    limiting the length (including the
  236.       NUL) to at most _e_r_r_b_u_f__s_i_z_e bytes.  If the whole message
  237.       won't    fit, as    much of    it as will fit before the terminating
  238.       NUL is supplied.  In any case, the returned value is the
  239.       size of buffer needed    to hold    the whole message (including
  240.       terminating NUL).  If    _e_r_r_b_u_f__s_i_z_e is 0, _e_r_r_b_u_f is ignored
  241.       but the return value is still    correct.
  242.  
  243.       If the _e_r_r_c_o_d_e given to _r_e_g_e_r_r_o_r is first ORed with
  244.       REG_ITOA, the    ``message'' that results is the    printable name
  245.       of the error code, e.g. ``REG_NOMATCH'', rather than an
  246.       explanation thereof.    If _e_r_r_c_o_d_e is REG_ATOI,    then _p_r_e_g
  247.       shall    be non-NULL and    the _r_e__e_n_d_p member of the structure it
  248.       points to must point to the printable    name of    an error code;
  249.       in this case,    the result in _e_r_r_b_u_f is    the decimal digits of
  250.       the numeric value of the error code (0 if the    name is    not
  251.       recognized).    REG_ITOA and REG_ATOI are intended primarily
  252.       as debugging facilities; they    are extensions,    compatible
  253.       with but not specified by POSIX 1003.2, and should be    used
  254.       with caution in software intended to be portable to other
  255.       systems.  Be warned also that    they are considered
  256.       experimental and changes are possible.
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                          (printed 5/3/99)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      RRRREEEEGGGGEEEEXXXX((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11117777 MMMMaaaayyyy 1111999999993333))))          RRRREEEEGGGGEEEEXXXX((((3333))))
  269.  
  270.  
  271.  
  272.       _R_e_g_f_r_e_e frees    any dynamically-allocated storage associated
  273.       with the compiled RE pointed to by _p_r_e_g.  The    remaining
  274.       _r_e_g_e_x__t is no    longer a valid compiled    RE and the effect of
  275.       supplying it to _r_e_g_e_x_e_c or _r_e_g_e_r_r_o_r is undefined.
  276.  
  277.       None of these    functions references global variables except
  278.       for tables of    constants; all are safe    for use    from multiple
  279.       threads if the arguments are safe.
  280.  
  281.      IIIIMMMMPPPPLLLLEEEEMMMMEEEENNNNTTTTAAAATTTTIIIIOOOONNNN CCCCHHHHOOOOIIIICCCCEEEESSSS
  282.       There    are a number of    decisions that 1003.2 leaves up    to the
  283.       implementor, either by explicitly saying ``undefined'' or by
  284.       virtue of them being forbidden by the    RE grammar.  This
  285.       implementation treats    them as    follows.
  286.  
  287.       See _r_e_g_e_x(7) for a discussion    of the definition of case-
  288.       independent matching.
  289.  
  290.       There    is no particular limit on the length of    REs, except
  291.       insofar as memory is limited.     Memory    usage is approximately
  292.       linear in RE size, and largely insensitive to    RE complexity,
  293.       except for bounded repetitions.  See BUGS for    one short RE
  294.       using    them that will run almost any system out of memory.
  295.  
  296.       A backslashed    character other    than one specifically given a
  297.       magic    meaning    by 1003.2 (such    magic meanings occur only in
  298.       obsolete [``basic''] REs) is taken as    an ordinary character.
  299.  
  300.       Any unmatched    [ is a REG_EBRACK error.
  301.  
  302.       Equivalence classes cannot begin or end bracket-expression
  303.       ranges.  The endpoint    of one range cannot begin another.
  304.  
  305.       RE_DUP_MAX, the limit    on repetition counts in    bounded
  306.       repetitions, is 255.
  307.  
  308.       A repetition operator    (?, *, +, or bounds) cannot follow
  309.       another repetition operator.    A repetition operator cannot
  310.       begin    an expression or subexpression or follow `^' or    `|'.
  311.  
  312.       `|' cannot appear first or last in a (sub)expression or
  313.       after    another    `|', i.e. an operand of    `|' cannot be an empty
  314.       subexpression.  An empty parenthesized subexpression,    `()',
  315.       is legal and matches an empty    (sub)string.  An empty string
  316.       is not a legal RE.
  317.  
  318.       A `{'    followed by a digit is considered the beginning    of
  319.       bounds for a bounded repetition, which must then follow the
  320.       syntax for bounds.  A    `{' _n_o_t    followed by a digit is
  321.       considered an    ordinary character.
  322.  
  323.       `^' and `$' beginning    and ending subexpressions in obsolete
  324.  
  325.  
  326.  
  327.      Page 5                          (printed 5/3/99)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      RRRREEEEGGGGEEEEXXXX((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11117777 MMMMaaaayyyy 1111999999993333))))          RRRREEEEGGGGEEEEXXXX((((3333))))
  335.  
  336.  
  337.  
  338.       (``basic'') REs are anchors, not ordinary characters.
  339.  
  340.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  341.       grep(1), regex(7)
  342.  
  343.       POSIX    1003.2,    sections 2.8 (Regular Expression Notation) and
  344.       B.5 (C Binding for Regular Expression    Matching).
  345.  
  346.      DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  347.       Non-zero error codes from _r_e_g_c_o_m_p and    _r_e_g_e_x_e_c    include    the
  348.       following:
  349.  
  350.       REG_NOMATCH     regexec() failed to match
  351.       REG_BADPAT     invalid regular expression
  352.       REG_ECOLLATE     invalid collating element
  353.       REG_ECTYPE     invalid character class
  354.       REG_EESCAPE     \ applied to unescapable character
  355.       REG_ESUBREG     invalid backreference number
  356.       REG_EBRACK     brackets [ ] not balanced
  357.       REG_EPAREN     parentheses ( ) not balanced
  358.       REG_EBRACE     braces    { } not    balanced
  359.       REG_BADBR     invalid repetition count(s) in    { }
  360.       REG_ERANGE     invalid character range in [ ]
  361.       REG_ESPACE     ran out of memory
  362.       REG_BADRPT     ?, *, or + operand invalid
  363.       REG_EMPTY     empty (sub)expression
  364.       REG_ASSERT     ``can't happen''-you found a bug
  365.       REG_INVARG     invalid argument, e.g.    negative-length    string
  366.  
  367.      HHHHIIIISSSSTTTTOOOORRRRYYYY
  368.       Written by Henry Spencer at University of Toronto,
  369.       henry@zoo.toronto.edu.
  370.  
  371.      BBBBUUUUGGGGSSSS
  372.       This is an alpha release with    known defects.    Please report
  373.       problems.
  374.  
  375.       There    is one known functionality bug.     The implementation of
  376.       internationalization is incomplete:  the locale is always
  377.       assumed to be    the default one    of 1003.2, and only the
  378.       collating elements etc. of that locale are available.
  379.  
  380.       The back-reference code is subtle and    doubts linger about
  381.       its correctness in complex cases.
  382.  
  383.       _R_e_g_e_x_e_c performance is poor.    This will improve with later
  384.       releases.  _N_m_a_t_c_h exceeding 0    is expensive; _n_m_a_t_c_h exceeding
  385.       1 is worse.  _R_e_g_e_x_e_c is largely insensitive to RE complexity
  386.       _e_x_c_e_p_t that back references are massively expensive.    RE
  387.       length does matter; in particular, there is a    strong speed
  388.       bonus    for keeping RE length under about 30 characters, with
  389.       most special characters counting roughly double.
  390.  
  391.  
  392.  
  393.      Page 6                          (printed 5/3/99)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      RRRREEEEGGGGEEEEXXXX((((3333))))        UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((11117777 MMMMaaaayyyy 1111999999993333))))          RRRREEEEGGGGEEEEXXXX((((3333))))
  401.  
  402.  
  403.  
  404.       _R_e_g_c_o_m_p implements bounded repetitions by macro expansion,
  405.       which    is costly in time and space if counts are large    or
  406.       bounded repetitions are nested.  An RE like, say,
  407.       `((((a{1,100}){1,100}){1,100}){1,100}){1,100}' will
  408.       (eventually) run almost any existing machine out of swap
  409.       space.
  410.  
  411.       There    are suspected problems with response to    obscure    error
  412.       conditions.  Notably,    certain    kinds of internal overflow,
  413.       produced only    by truly enormous REs or by multiply nested
  414.       bounded repetitions, are probably not    handled    well.
  415.  
  416.       Due to a mistake in 1003.2, things like `a)b'    are legal REs
  417.       because `)' is a special character only in the presence of a
  418.       previous unmatched `('.  This    can't be fixed until the spec
  419.       is fixed.
  420.  
  421.       The standard's definition of back references is vague.  For
  422.       example, does    `a\(\(b\)*\2\)*d' match    `abbbd'?  Until    the
  423.       standard is clarified, behavior in such cases    should not be
  424.       relied on.
  425.  
  426.       The implementation of    word-boundary matching is a bit    of a
  427.       kludge, and bugs may lurk in combinations of word-boundary
  428.       matching and anchoring.
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.      Page 7                          (printed 5/3/99)
  460.  
  461.  
  462.  
  463.